import {Command} from '../constant';
import Taro from '@tarojs/taro';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';
import api from 'api';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },
    async page() {
      let uniqueID = Taro.getStorageSync('uniqueID');
      let params = {
        deviceNum: uniqueID,
      };
      let res = await api.forumController.getForumTitleList(params);
      if (res.success) {
        action.commonChange('main.tabList', res.data);
      }
    },
    /**
     * 初始化
     */
    async query() {},
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageBCommunityNewPostMain'),
  };
}

//create by moon https://github.com/creasy2010/moon
